package com.tz.farmer.controller;

import com.smartPark.msframe.result.ResultEx;
import com.tz.farmer.service.IFarmerSunDataService;
import com.tz.farmer.so.DefaultSo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/factory")
@Api(tags = "阳光工厂接口")
public class FarmerFactoryController {

    private static final String enterpriseKey = "enterpriseKey";
    private static final String factoryKey = "factoryKey";
    private static final String deviceKey = "deviceKey";
    private static final String market = "阳光工厂";

    @Autowired
    private IFarmerSunDataService dataService;

    @PostMapping("/set")
    @ApiOperation(value = "设置阳光市场数量")
    public ResultEx setFactoryConfig(@RequestBody DefaultSo body) {
        dataService.setSunData(body, market, factoryKey, enterpriseKey, deviceKey);

        return ResultEx.builder().makeSuccessResult();
    }

    @GetMapping("/get")
    @ApiOperation(value = "获取阳光工厂数据")
    public ResultEx getFactoryConfig() {
        Map<String, Object> response = dataService.getSunData(market, factoryKey, enterpriseKey, deviceKey);

        return ResultEx.builder().makeSuccessResult(response);
    }
}
